package errors

import (
	"fmt"
)

// GetErrorResponse returns a formatted error response for a given platform and error code
func GetErrorResponse(platform, code string) map[string]interface{} {
	config := GetErrorConfig(platform, code)
	if config == nil {
		// Return a default error response if the code is not found
		return map[string]interface{}{
			"code":    "9999",
			"message": "未知错误",
			"status":  StatusFailed,
		}
	}

	return map[string]interface{}{
		"code":    config.Code,
		"message": config.Message,
		"status":  config.Status,
	}
}

// FormatErrorMessage formats an error message with additional parameters
func FormatErrorMessage(message string, params ...interface{}) string {
	if len(params) == 0 {
		return message
	}
	return fmt.Sprintf(message, params...)
}

// IsSuccess checks if the error code indicates a successful operation
func IsSuccess(code string) bool {
	return code == "0000"
}

// IsFailed checks if the error code indicates a failed operation
func IsFailed(code string) bool {
	config := GetErrorConfig("photonpay", code)
	if config == nil {
		return true
	}
	return config.Status == StatusFailed
}

// IsPending checks if the error code indicates a pending operation
func IsPending(code string) bool {
	config := GetErrorConfig("photonpay", code)
	if config == nil {
		return false
	}
	return config.Status == StatusPending
}

// IsSuspended checks if the error code indicates a suspended operation
func IsSuspended(code string) bool {
	config := GetErrorConfig("photonpay", code)
	if config == nil {
		return false
	}
	return config.Status == StatusSuspend
}
